package com.msmall.community.roster.model;

import javax.persistence.Transient;

import com.msmall.base.model.BaseObject;
import com.msmall.base.util.ConstantDB;

/**
 * 用户关系的帮助类，对应2条记录 Roster.java RosterGroup.java
 */
public class RosterItem extends BaseObject{

	private static final long serialVersionUID = -2024216079815136724L;

	private Long pubUserid;//用户A的ID
	private Long pubGroupid;//用户A的好友B所在的组ID Group.java ID
	private String pubGroupName;//用户A的好友B所在的组名
	private Long pubRosterid;//用户A的好友B的关系ID Roster.java ID
	private Integer pub;//用户A对好友B的关系
	private String pubNickname;//用户A对好友B的备注
	
	private Long subUserid;//用户B的ID
	private Long subGroupid;//用户B的好友A所在的组ID
	private String subGroupName;//用户B的好友A所在的组名
	private Long subRosterid;//用户B的好友A的关系ID
	private Integer sub;//用户B对好友A的关系
	private String subNickname;//用户B对好友A的备注
	
	public RosterItem(){}
	
	public RosterItem(Roster pub, Roster sub){
		if(pub != null && sub != null){
			RosterGroup pubg = pub.getGroup();
			RosterGroup subg = sub.getGroup();
			setPubUserid(pub.getUserid());
			setPubGroupid(pubg.getGroupid());
			setPubGroupName(pubg.getName());
			setPubRosterid(pub.getRosterid());
			setPub(pub.getStatus());
			setPubNickname(pub.getNickname());
			
			setSubUserid(sub.getUserid());
			setSubGroupid(subg.getGroupid());
			setSubGroupName(subg.getName());
			setSubRosterid(sub.getRosterid());
			setSub(sub.getStatus());
			setSubNickname(sub.getNickname());
		}
	}

	@Transient
	public int getStandFor(){
		return getStand(pub, sub);
	}
	/** 表示pub和sub之间的关系: 值=1：请求;值=2同意；值=-1未处理；值=-2拒绝;值=-3黑名单；值=-4被黑名单</br>
	 * 当pub向sub发送好远请求时pub=1 sub=-1(单向好友) 返回：1</br>
	 * 当sub向pub发送好远请求时pub=-1 sub=1(单向好友) 返回：2</br>
	 * 如果拒绝(双方) pub=-2 sub=-2 返回：3</br>
	 * 如果同意(双方好友) pub=2 sub=2 返回：4</br>
	 * pub黑名单sub：pub=-3 sub=-4  返回：5</br>
	 * sub黑名单pub：pub=-4 sub=-3  返回：6</br>
	 * 在好友情况下：在此发送好友请求无效,如果一方删除，则双方都删除关系</br>
	 * 在拒绝情况下：依然接受请求</br>
	 * pub 向 sub 发请求 pub=1 sub=-2 返回：7</br>
	 * sub 向 pub 发请求 pub=-2 sub=-1 返回：8</br>
	 * 在黑名单情况下：不在接受好友请求</br>
	 */
	@Transient
	public static int getStand(int pub, int sub){
		if(pub == ConstantDB.ROSTER_REQUEST && sub == ConstantDB.ROSTER_UNHANDLE){
			return 1;
		}else if(pub == ConstantDB.ROSTER_UNHANDLE && sub == ConstantDB.ROSTER_REQUEST){
			return 2;
		}else if(pub == ConstantDB.ROSTER_REJECT && sub == ConstantDB.ROSTER_REJECT){
			return 3;
		}else if(pub == ConstantDB.ROSTER_AGREE && sub == ConstantDB.ROSTER_AGREE){
			return 4;
		}else if(pub == ConstantDB.ROSTER_BLACKLIST && sub == ConstantDB.ROSTER_FORBIDDEN){
			return 5;
		}else if(pub == ConstantDB.ROSTER_FORBIDDEN && sub == ConstantDB.ROSTER_BLACKLIST){
			return 6;
		}else if(pub == ConstantDB.ROSTER_REQUEST && sub == ConstantDB.ROSTER_REJECT){
			return 7;
		}else if(pub == ConstantDB.ROSTER_REJECT && sub == ConstantDB.ROSTER_REQUEST){
			return 8;
		}else{
			return 0;
		}
	}
	public Long getPubUserid() {
		return pubUserid;
	}
	public void setPubUserid(Long pubUserid) {
		this.pubUserid = pubUserid;
	}
	public Long getPubGroupid() {
		return pubGroupid;
	}
	public void setPubGroupid(Long pubGroupid) {
		this.pubGroupid = pubGroupid;
	}
	public String getPubGroupName() {
		return pubGroupName;
	}
	public void setPubGroupName(String pubGroupName) {
		this.pubGroupName = pubGroupName;
	}
	public Long getPubRosterid() {
		return pubRosterid;
	}
	public void setPubRosterid(Long pubRosterid) {
		this.pubRosterid = pubRosterid;
	}
	public Integer getPub() {
		return pub;
	}
	public void setPub(Integer pub) {
		this.pub = pub;
	}
	public String getPubNickname() {
		return pubNickname;
	}
	public void setPubNickname(String pubNickname) {
		this.pubNickname = pubNickname;
	}
	public Long getSubUserid() {
		return subUserid;
	}
	public void setSubUserid(Long subUserid) {
		this.subUserid = subUserid;
	}
	public Long getSubGroupid() {
		return subGroupid;
	}
	public void setSubGroupid(Long subGroupid) {
		this.subGroupid = subGroupid;
	}
	public String getSubGroupName() {
		return subGroupName;
	}
	public void setSubGroupName(String subGroupName) {
		this.subGroupName = subGroupName;
	}
	public Long getSubRosterid() {
		return subRosterid;
	}
	public void setSubRosterid(Long subRosterid) {
		this.subRosterid = subRosterid;
	}
	public Integer getSub() {
		return sub;
	}
	public void setSub(Integer sub) {
		this.sub = sub;
	}
	public String getSubNickname() {
		return subNickname;
	}
	public void setSubNickname(String subNickname) {
		this.subNickname = subNickname;
	}
	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

}
